//配置车间开料员、新开料员根据年份、月份、岗位名称、部门代码来填充表中数据
function addPZCJData(elementIdName,postName,pkDept,year,month){ //table中的属性id名称，岗位名称，岗位id，部门代码，月份，年份
    //根据部门和岗位名称获取岗位子类型的岗位
    var post = commonAjax("post","/jxIndex/selectSonPost",{postName:postName,pkDept:pkDept});
    var postIds = post.obj;  // 获取所有岗位的编码(数组)，
    var d={postName:postName,postId: postIds.join(","),pkDept:pkDept,month:month,year:year}
    d=JSON.stringify(d);
    //根据岗位和部门获取用户信息
    var users = commonAjax("post","/jxIndex/pzcj/getEmpByPkDeptAndPostIds",d,"application/json;charset=utf-8");

    users.forEach(function (user) {
        var rPostName = user.postName;
        //处理每个不同表需要添加员工信息数据和字段
        var empName=user.empName;   //员工姓名
        var empCode=user.empCode;   //员工工号
        var postName=rPostName;   //员工岗位名称
        var rowObj={empName: empName,empCode: empCode,postName: postName};
        var empGroup = user.empGroup;
        if (empGroup){
            rowObj.empGroup= empGroup                                  //班组
        }
        var productivity = user.productivity;                          //个人生产效率
        if (productivity){
               rowObj.productivity=productivity;
        }
        var dabanSuccess=  user.dabanSuccess;                          //一次打板成功率(%)
        if(dabanSuccess){
            rowObj.dabanSuccess=dabanSuccess;
        }
        var dabanMoney= user.dabanMoney ;                               //第一次打板金额(B1）
        if (dabanMoney){
            rowObj.dabanMoney=dabanMoney;
        }
        var deduct=user.deduct;
        if (deduct){
            rowObj.deduct= deduct;                                      //绩效扣款
        }
        var attendanceRate=user.attendanceRate;
        if (attendanceRate){
            rowObj.attendanceRate= attendanceRate ;                     //出勤率
        }
        var workshopEfficiency = user.workshopEfficiency;
        if (workshopEfficiency){
            rowObj.workshopEfficiency=workshopEfficiency
        }
        var empEntry=user.empEntry;                                   //考核月份：两表不统一
        var entryMonth=user.entryMonth;
        if (empEntry){
            rowObj.entryMonth=  empEntry;                             //查询用户表获取数据
        }else {
            rowObj.entryMonth=  entryMonth;                            //查询绩效表获取数据
        }

        var teamAvgBonus = user.teamAvgBonus;                           //班组平均绩效奖金
        if (teamAvgBonus){
            rowObj.teamAvgBonus=teamAvgBonus;
        }
        var performanceBonus = user.performanceBonus;                   //绩效奖金
        if (performanceBonus){
            rowObj.performanceBonus=performanceBonus;
        }

        //默认85，5S及目视化管理得分

        var score5s = user.score5s;                       //5S及目视化管理得分
        if(score5s){
            rowObj.score5s=score5s;
        }else {
            rowObj.score5s=85;
        }
        var penalty5s = user.penalty5s;                       //5S及目视化管理得扣款
        if(penalty5s){
            rowObj.penalty5s=penalty5s;
        }else {
            rowObj.penalty5s=0;
        }

        var teamTotalBonus = user.teamTotalBonus;
       // if (teamTotalBonus) {
            rowObj.teamTotalBonus = teamTotalBonus;
       // }
        var teamEfficiency = user.teamEfficiency;                       //班组效率
        if(teamEfficiency){
            rowObj.teamEfficiency=teamEfficiency;
        }
        var penaltyQuality = user.penaltyQuality;                       //质量要求扣款
        if(penaltyQuality){
            rowObj.penaltyQuality=penaltyQuality;
        }
        var penaltyEveryday=user.penaltyEveryday;                       //日常检查扣款
        if (penaltyEveryday){
            rowObj.penaltyEveryday=penaltyEveryday;
        }
        var weighingAccuracy=user.weighingAccuracy;                       //日常检查扣款
        if (weighingAccuracy){
            rowObj.weighingAccuracy=weighingAccuracy;                      //称料不准确
        }
        var weighingTimely=user.weighingTimely;                       // 称料不及时
        if (weighingTimely){
            rowObj.weighingTimely=weighingTimely;
        }

        var resultMoney = user.resultMoney;                             //最终综合绩效
        if (resultMoney){
            rowObj.resultMoney=resultMoney;
        }

        $("#"+elementIdName).edatagrid('addRow',{row:rowObj})
    })

    //循环完后：保存和清除选中
    $("#"+elementIdName).edatagrid('saveRow');
    $("#"+elementIdName).edatagrid('clearSelections')
}

//包装车间
function addBZCJData(elementId,postName,year,month,empGroup){
    console.log("addBZCJData")
    var datas=commonAjax("post","/jx/bzcj/selectJxAssessBzcj",{postName:postName,year:year,month:month,empGroup:empGroup,pkDept:window.bzcj_currentDept})
    datas.forEach(function (val) {

        //把数据插入表中
        $("#"+elementId).edatagrid('addRow',{row:{
            empName:val.empName,
            empCode:val.empCode,
            postName:val.postName,
            empGroup:val.empGroup,                      //班组
            zuZhangName:val.zuZhangName,                    //所属班组
            teamEfficiency:val.teamEfficiency,              //产线生产<br/>效率(%)
            performanceBonusNorm:val.performanceBonusNorm,    //绩效奖金<br/>标准
            efficiencyBonus:val.efficiencyBonus,               //效率奖金
            lossRate:val.lossRate,                              //损耗率
            lossBonus:val.lossBonus,                        //损耗奖金
            score5s:val.score5s,                        //5s得分
            penalty5s:val.penalty5s,                    //规范化<br/>奖金
            penaltyDayRate:val.penaltyDayRate,          //质量天数<br/>比率(%)
            penaltyBonusNorm:val.penaltyBonusNorm,      //质量奖金<br/>标准
            penaltyBonus:val.penaltyBonus,               //质量奖金
            attendanceRate:val.attendanceRate,              //出勤率
            exceptionBonus:val.exceptionBonus,              //发现异常<br/>奖金
            illegalFine:val.illegalFine,                    //违规扣款
            resultMoney:val.resultMoney,                    //综合绩效奖金
            remarks:val.remarks,                            //备注
            assessType:val.assessType,                            //绩效类型
             zhuGuanName:val.zhuGuanName                             //所属主管
        }})
    })
    //循环完后：保存和清除选中
    $("#"+elementId).edatagrid('saveRow');
    $("#"+elementId).edatagrid('clearSelections')
}
